<template>
  <ElConfigProvider :locale="zhCn">
    <loading v-if="data.show" text=""/>
    <router-view></router-view>
  </ElConfigProvider>
</template>
<script lang="ts" setup>
import {onMounted} from "vue";
import {useRoute} from 'vue-router'
import store from '@/store'
import zhCn from 'element-plus/lib/locale/lang/zh-cn';
import './App.css';
import {Session, Local} from '@/utils/storage';
const route = useRoute()
import loading from './components/loading/loading.vue'
import { ref, getCurrentInstance,watch } from 'vue'
import chat from "@/api/chat";
import bus from 'vue3-eventbus'
const { proxy } = getCurrentInstance()
const data = reactive({
  show: false
})
onMounted(() => {
  bus.on('chatLogin', (e: any) => {
    chatInfo()
  })
  chatInfo()
})
const chatInfo = () => {
  console.log(route.query,'=====================================================>')
  //原因，因为IM的登录是异步的，所以需要等到登录成功后再显示
  if(Session.get('ZJ_token') || route.query.initialize){
    data.show = true
    chat.chatLogin(proxy.$chat).then((res:any) => {
      if (res.data.actionStatus === 'OK'){
        console.log('重要的',res)
        setTimeout(() => {
          store.commit('setIM', '1')
          data.show = false
        },2000)
      }
    }).catch((err:any) => {
      data.show = false
    })
  }
}
</script>
